<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>续签停车场合同</title>
<jsp:include page="../../import.jsp" flush="true" />
<jsp:include page="assParkCommon.jsp" flush="true" /><!-- 时间格式转换 -->
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="parkingLot">
			<div class="fieldset1 tabel_col clearFix">
				<div class="caption">
					<span class="title">续签停车场合同</span>
				</div>
				<div class="fieldBox col_33">
					<div class="label">停车场编号</div>
	                <div class="field">
	                    <span id="parkCd" name="parkCd">&nbsp;</span>
	                </div>
				</div>
	            <div class="fieldBox col_33">
					<div class="label">停车场名称</div>
					<div class="field">
						<span id="parkNm" name="parkNm">&nbsp;</span>
					</div>
				</div>
				<div class="fieldBox col_33">
					<div class="label">停车场联系人</div>
					<div class="field test_combo">
						<span id="contactNm" name="contactNm">&nbsp;</span>
					</div>
				</div>
	            <div class="fieldBox col_33">
	                <div class="label">停车场联系人电话</div>
	                <div class="field">
	                    <span id="contactTel" name="contactTel">&nbsp;</span>
	                </div>
	            </div>
	            <div class="fieldBox col_66_auto">
					<div class="label">停车场城市</div>
					<div class="field">
						<span id="provinceCity" name="provinceCity">${provinceCity}</span>
					</div>
				</div>
	            <!-- 可修改 -->
				<div class="fieldBox col_100_auto">
					<div class="label">合同有效期</div>
					<div class="field">
						<input name="beginDt" id="beginDt" type="text" class="ui-datepicker" value="" validate="{required:true}">
						<span>---</span>
						<input name="endDt" id="endDt" type="text" class="ui-datepicker" value="" validate="{required:true}">
						<span class="requiredSymbol">*</span>
					</div>
				</div>
	            <div class="fieldBox col_100">
					<div class="label">停车场地址</div>
					<div class="field">
						<span id="parkAddress" name="parkAddress">&nbsp;</span>
					</div>
				</div>
				<div class="fieldBox col_100">
					<div class="label">资产管理员</div>
					<div class="field" style="width: 100%;">
						<span id="assMgList" name="assMgList">
							<c:forEach items="${assMgsList}" var="assMgs">
	                            ${assMgs.managerRlNm}[${assMgs.managerNm}]&nbsp;&nbsp;
							</c:forEach>
						</span>
					</div>
				</div>
				<div class="fieldBox col_100">
					<div class="label">附件上传</div>
					<div class="field">
						<jsp:include page="../assCommFilesUpload.jsp" flush="true" >
							<jsp:param name="filePath" value="ass"/>
						</jsp:include>
						<div id="fileUpload1" class="upfileBoxs"></div>
						<span class="sq-button sq-button-hasicon" id="btnUpload1" onclick="ajaxFileUploadImg('uploads1',1)">
							<i class="sqBtnIco_9"></i>上传
						</span>
					</div>
				</div>
				<div class="fieldBox col_100">
					<div style="width: 98%; margin-left: 1%;">
						<jsp:include page="../assCommFilesList.jsp" flush="true" ></jsp:include>
						<div id="ligergrid_file1" class="sq-grid"></div>
					</div>
				</div>
				<!-- 隐藏主键、系统代码(融资租赁系统)、用户状态(启用)、有效期ID -->
                <div class="fieldBox col_100" style="display:none;">
                    <div class="field">
                         <input name="pId" id="pId" type="text" class="ui-textbox" value="${id}">
                         <input name="searchSysCd" id="searchSysCd" type="text" class="ui-textbox" value="11000">
                         <input name="isValid" id="isValid" type="text" class="ui-textbox" value="1">
                         <input name="validId" id="validId" type="text" class="ui-textbox" value="${validId}">
                         <input name="validIdList" id="validIdList" type="text" class="ui-textbox" value="${validIdList}">
                         <!-- 上传文件使用：系统时间和当前登录人姓名 -->
                         <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
                         <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
                         <!-- 原有效期-控制是否需要修改 -->
                         <input name="beginDt_base" id="beginDt_base" type="text" class="ui-datepicker" value="">
                         <input name="endDt_base" id="endDt_base" type="text" class="ui-datepicker" value="">
                         <input name="isBegin" id="isBegin" type="text" class="ui-textbox" value="0">
                         <input name="isEnd" id="isEnd" type="text" class="ui-textbox" value="0">
                    </div>
                </div>
			</div>
			
			<div class="fieldset1 tabel_col tabel_col_s clearFix">
				<div class="caption">
					<span class="title">历史信息</span>
				</div>
				<div class="fieldBox col_100">
	            	<div id="ligergrid_file2" class="sq-grid"></div>
				</div>
			</div>
			
			<div class="btnsBox">
				<span id="renewBtn" class="sq-button sq-button-round" onclick="renew()">修改</span>
				<span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab()">关闭</span>
			</div>
			</form>
		</div>
	</div>

    <script>
	    $(function() {
	    	initForm();//初始化表单
	    	initData();//初始化数据
	    	loadFilesLiger("tccfj", 1, $("#validId").val());//加载停车场文件列表信息
	    	loadFilesLiger("tcclsfj", 2, $("#validIdList").val());//加载停车场历史文件列表信息
	    });
	    
	  	//判断有效期-开始时间
    	function beginDtChange() {
    		var beginDt_val=$("#beginDt").val();
    		var beginDt_base=$("#beginDt_base").val();
    		var endDt_base=$("#endDt_base").val();
    		if(beginDt_val==beginDt_base){
    			return false;
    		}
    		if(beginDt_val < endDt_base){
    			$.ligerDialog.SQalert({content: "新有效期开始时间应大于原有效期结束时间！",SQ_type: "warning"});
    			$("#beginDt").val("");
    			$("#isBegin").val("0");
    		}else{
    			$("#isBegin").val("1");
    		}
    	}
    	//判断有效期-结束时间
    	function endDtChange() {
    		var endDt_val=$("#endDt").val();
    		var beginDt_val=$("#beginDt").val();
    		var endDt_base=$("#endDt_base").val();
    		if(endDt_val==endDt_base){
    			return false;
    		}
    		if(endDt_val < beginDt_val){
    			$.ligerDialog.SQalert({content: "有效期结束时间应大于有效期开始时间！",SQ_type: "warning"});
    			$("#endDt").val("");
    			$("#isEnd").val("0");
    		}else{
    			$("#isEnd").val("1");
    		}
    	}
	    
	  	//初始化表单
	    function initForm(){
	    	//绑定change事件
			$("#beginDt").ligerDateEditor({
				onChangeDate: function (value) {
					beginDtChange();
				}
			});
			$("#endDt").ligerDateEditor({
				onChangeDate: function (value) {
					endDtChange();
				}
			});
			//初始化表单
	    	$("#parkingLot").ligerForm({
				validate: true
			});
			$("#parkingLot").check_ligerFormEditor();//重新刷新页面动态字段
		};
	    
	    function initData(){
	    	var _id = $("#pId").val();
	    	if(!_id)return;
	    	var wait_dialog= $.ligerDialog.SQalert({
	            content: LogUtils.LOG_CMM_LOADING,
	            SQ_type: "waitting",
	            onClose: function () {
	            }
	        });
	    	
	    	var _url = '<%=path%>/ass/assParking/getById.do';
	    	$.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{id:_id},
	    		url: _url,
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				 setData(msg.data);//设置数据
	    			 }else{
	    				 $.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    			 }
	    		}
	    	});
	    }
	
	    //设置页面数据
	    function setData(data){
	    	$("#parkCd").html(data.parkCd);
	    	$("#parkNm").html(data.parkNm);
	    	$("#parkAddress").html(data.parkAddress);
	    	$("#contactNm").html(data.contactNm);
	    	$("#contactTel").html(data.contactTel);
	    	//加载表单
	    	var form = liger.get("parkingLot");
			form.setData({
				validId: data.validId,
				beginDt: renderDate1(data.beginDt),
				endDt: renderDate1(data.endDt),
				beginDt_base: renderDate1(data.beginDt),
				endDt_base: renderDate1(data.endDt)
	    	});
			//加载日期插件
			$("#beginDt").trigger("change");
			$("#endDt").trigger("change");
	    }
		
		//续签合同-延长有效期
		function renew(){
			var ligerForm = liger.get("parkingLot");
			if (!ligerForm.valid()) {
				$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
				return false; //验证不通过，不执行以下代码
			}
			//判断合同有效期
			var beginDt = $("#beginDt").val();
			var endDt = $("#endDt").val();
			if(beginDt > endDt){
				$.ligerDialog.SQalert({content: "输入的合同有效期-终止日期应大于起始日期！",SQ_type: "warning"});
				return false;
			}
			//获取停车场ID-不为空执行
			var pId = $("#pId").val();
			if(pId){//不为空执行
				//获取表单数据
				var data = ligerForm.getData();
				//获取停车场有效期ID-不为空执行
				var vId = $("#validId").val();
				if(vId){//不为空执行
					//修改停车场有效期信息
					url = '<%=path%>/ass/assParkingValid/modify.do';
					data["parkId"] = $("#pId").val();
					data["validId"] = vId;
					$.ajax({
						type: 'post',
						dataType: 'json',
						data: data,
						url: url,
						beforeSend: function(){
							wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						},
						success:function(msg){
							wait_dialog.close();
							//返回的停车场有效期ID不为空成功
							if(msg.success == 1 && null != msg.data){
								$("#validId").val(msg.data);
								saveFile(msg.info);//保存文件
							}else{
								$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
							}
						}
					});
				}
			}
		}
		
		//显示已上传但是未保存的文件列表
		function showFiles(data, index){
			var sysDate = $("#sysDate").val();
			var loginUsrNm = $("#loginUsrNm").val();
			var f_Grid = liger.get("ligergrid_file"+index);
			var uploadJOSN = data;
    		for (var i=0; i< uploadJOSN.length; i++){ 
        		//添加行-追加行
        		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index});
    		}
		}
		
		//保存文件
		function saveFile(info){
			var docArray = JSON.stringify(getUploadResultParams(1));
	        var url = "<%=path%>/ass/assParking/uploadAttchment.do";
	        var validId = $("#validId").val();
        	if(null == docArray){
        		$.ligerDialog.SQalert({content: info,SQ_type: "success"});
        		return false;
        	}
	        if(validId){//有效期ID不为空执行
		        //赋值附件
		        var data = {
					"docArray":docArray,
					"validId":validId
				};
				//请求
		        AjaxUtils.ajaxPost(url, data, function(msg){
		        	if(msg.success == 1){
						 $.ligerDialog.SQalert({content: info,SQ_type: "success"});
						 if(msg.data){
							 //刷新附件页面GRID方法和清空上传按钮
							 //refreshUlFileRecList(1);
							 clearUploadResultParams(1);
						 }
					 }else{
						 UIUtils.alertError(msg.info);
					 }
		        }, true);
	        }else{
	        	$.ligerDialog.SQalert({content: "业务主键为空-不能保存文件！",SQ_type: "error"});
	        }
		}
    </script>
</body>
</html>